package com.hnkywl.sts.entity.xsgl;

import com.hnkywl.sts.entity.BaseEntity;
import com.hnkywl.sts.entity.organ.Ck;
import com.hnkywl.sts.entity.sys.Yg;
import org.hibernate.annotations.Formula;
import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 13-5-25
 * Time: 下午2:22
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "T_BIZ_KCPD")
@Where(clause = "deleted!='1'")
public class Kcpd extends BaseEntity {
    @Id
    @SequenceGenerator(name = "seqKcpd", allocationSize = 1, sequenceName = "SEQ_BIZ_KCPD")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seqKcpd")
    private Long id;

    /**
     *盘存单号
     */
    private String kcpdbm;

    /**
     * 盘点仓库
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CK_ID")
    private Ck pdck;

    /**
     * 盘点日期
     */
    private Date pdrq;

    /**
     * 盘点月份
     */
    private String pdyf;

    /**
     * 账面金额
     */
    @Formula("(select sum(A.ZMSL*A.WSDJ) from T_BIZ_PDMX A where A.KCPD_ID=ID and A.DELETED!=1)")
    private Double zmje;

    /**
     * 实盘金额
     */
    @Formula("(select sum(A.SPSL*A.WSDJ) from T_BIZ_PDMX A where A.KCPD_ID=ID and A.DELETED!=1)")
    private Double spje;

    /**
     * 盈亏金额
     */
    @Formula("(select sum(A.YKSL*A.WSDJ) from T_BIZ_PDMX A where A.KCPD_ID=ID and A.DELETED!=1)")
    private Double ykje;

    /**
     * 盈亏数量
     */
    @Formula("(select sum(A.YKSL) from T_BIZ_PDMX A where A.KCPD_ID=ID and A.DELETED!=1)")
    private Double yksl;

    /**
     * 盘点人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PDR_ID")
    private Yg pdr;

    /**
     * 审核人
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SHRY_ID")
    private Yg shry;

    /**
     * 审核日期
     */
    private Date shrq;

    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.LAZY,mappedBy = "kcpd",targetEntity = Pdmx.class)
    @Where(clause = "deleted!='1'")
    private List<Pdmx> pdmxList;

    /**
     * 是否生成盘点表
     */
    private boolean sfscpdb = false ;

    /**
     * 是否审核
     */
    private boolean sfsh = false;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getKcpdbm() {
        return kcpdbm;
    }

    public void setKcpdbm(String kcpdbm) {
        this.kcpdbm = kcpdbm;
    }

    public Ck getPdck() {
        return pdck;
    }

    public void setPdck(Ck pdck) {
        this.pdck = pdck;
    }

    public Date getPdrq() {
        return pdrq;
    }

    public void setPdrq(Date pdrq) {
        this.pdrq = pdrq;
    }

    public String getPdyf() {
        return pdyf;
    }

    public void setPdyf(String pdyf) {
        this.pdyf = pdyf;
    }

    public Double getZmje() {
        return zmje;
    }

    public void setZmje(Double zmje) {
        this.zmje = zmje;
    }

    public Double getSpje() {
        return spje;
    }

    public void setSpje(Double spje) {
        this.spje = spje;
    }

    public Double getYkje() {
        return ykje;
    }

    public void setYkje(Double ykje) {
        this.ykje = ykje;
    }

    public Double getYksl() {
        return yksl;
    }

    public void setYksl(Double yksl) {
        this.yksl = yksl;
    }

    public Yg getPdr() {
        return pdr;
    }

    public void setPdr(Yg pdr) {
        this.pdr = pdr;
    }

    public Yg getShry() {
        return shry;
    }

    public void setShry(Yg shry) {
        this.shry = shry;
    }

    public Date getShrq() {
        return shrq;
    }

    public void setShrq(Date shrq) {
        this.shrq = shrq;
    }

    public List<Pdmx> getPdmxList() {
        return pdmxList;
    }

    public void setPdmxList(List<Pdmx> pdmxList) {
        this.pdmxList = pdmxList;
    }

    public boolean isSfscpdb() {
        return sfscpdb;
    }

    public void setSfscpdb(boolean sfscpdb) {
        this.sfscpdb = sfscpdb;
    }

    public boolean getSfsh() {
        return sfsh;
    }

    public void setSfsh(boolean sfsh) {
        this.sfsh = sfsh;
    }
}
